package breeze.update.album;
import android.content.Context;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.io.DataInputStream;
import java.util.ArrayList;

public class FileUtils {
    
    /*
	*@author BREEZE
	*@date 2021-10-02 07:55:26
    */
	private Context mContext;
	
	private File file_path;
	
	public FileUtils(Context context){
		mContext = context;
		file_path = new File(context.getExternalFilesDir("data")+"/hidden.txt");
		if(!file_path.exists()){
			try {
				file_path.createNewFile();
			} catch (IOException e) {}
		}
	}
	
	public void addData(String path){
		try {
			FileOutputStream output = new FileOutputStream(file_path, true);
			output.write((path+"\n").getBytes());
			output.close();
		} catch (Exception e) {}
	}
	
	public List<String> getDatas(){
		try{
			List<String> list = new ArrayList<String>();
			FileInputStream input = new FileInputStream(file_path);
			DataInputStream inputstream = new DataInputStream(input);
			String line;
			while((line = inputstream.readLine())!=null){
				list.add(line);
			}
			input.close();
			inputstream.close();
			return list;
		}catch(Exception e){
			return null;
		}
	}
	
	public void delete(String path){
		try{
			FileInputStream input = new FileInputStream(file_path);
			byte[] bytes = new byte[input.available()];
			input.read(bytes);
			String str = new String(bytes);
			input.close();
			str = str.replace(path+"\n","");
			
			FileOutputStream output = new FileOutputStream(file_path);
			output.write(str.getBytes());
			output.close();
		}catch(Exception e){
			
		}
	}

    
}
